﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTS
{
    class AlgorithmEMA : Algorithm
    {
        int Period;
        public Double factor;
        public AlgorithmEMA(int days)
        {
            Period = days;
            this.name = "EMA" + days.ToString();
            factor = 1.01;
        }
        public AlgorithmEMA()
        {
            Period = 30;
            this.name = "EMA30";
            factor = 1.01;
        }
        public void setFactor(Double val)
        {
            factor = val;
        }
        public override int getDecision(HistoriaSpolki hs, DateTime Today)
        {
            var hsPrep = hs.getPrevOfData(Today, Period);
            if (hsPrep.getDane().Count == 0) return 0;
            List<Double> wartosc = new List<double>();
            foreach (var tmp in hsPrep.getDane())
                wartosc.Add(tmp.GetClose());
            Double wynikEMA = Pomocnik.EMA(wartosc);
            Console.WriteLine(factor);
            if (wartosc[0] > wynikEMA * factor && wartosc[1] < wynikEMA * factor)
                return 1;
            if (wartosc[0] < wynikEMA * (1 / factor) && wartosc[1] > wynikEMA * (1 / factor))
                return -1;
            return 0;
        }
        public override int getDecision(HistoriaSpolki hs, double cena, DateTime Today)
        {
            var hsPrep = hs.getPrevOfData(Today, Period);
            if (hsPrep.getDane().Count == 0) return 0;
            List<Double> wartosc = new List<double>();
            foreach (var tmp in hsPrep.getDane())
                wartosc.Add(tmp.GetClose());
            Double wynikEMA = Pomocnik.EMA(wartosc);
            if (cena > wynikEMA * factor && wartosc[0] < wynikEMA * factor)
                return 1;
            if (cena < wynikEMA * (1 / factor) && wartosc[0] > wynikEMA * (1 / factor))
                return -1;
            return 0;
        }
    }
}
